import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:x_core/x_core.dart';
import 'package:x_module_copy/pages/copy/copy_controller.dart';
import 'package:x_module_copy/pages/copy/copy_state.dart';
import 'package:x_project/x_project.dart';

/// Created by XieXin on 2020/3/18.
/// Copy
class CopyPage extends GetView<CopyController> {
  final CopyState state = Get.find<CopyController>().state;

  CopyPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const XAppBar(title: "登录账号"),
      body: GetBuilder<CopyController>(
        builder: (c) => XScrollView(
          keyboardConfig: Utils.getKeyboardActionsConfig(
              context, [controller.nodeText1, controller.nodeText2]),
          padding: EdgeInsets.only(top: 20.h, left: 55.w, right: 55.w),
          children: _buildBody,
        ),
      ),
    );
  }

  get _buildBody => [
        Text("登录接收数据：${state.login.toString()}"),
        SizedBox(height: 150.h),
        XTextField(
          key: const Key("mobile"),
          controller: controller.mobileController,
          focusNode: controller.nodeText1,
          fontSize: 32.sp,
          maxLength: 11,
          bottomPadding: 10.h,
          keyboardType: TextInputType.phone,
          hintText: "请输入手机号",
          getVCode: () {
            return Future.value(true);
          },
        ),
        SizedBox(height: 32.h),
        XTextField(
          key: const Key("password"),
          controller: controller.passwordController,
          focusNode: controller.nodeText2,
          fontSize: 32.sp,
          maxLength: 16,
          bottomPadding: 10.w,
          hintText: "请输入密码",
          isInputPwd: true,
          rightText: "忘记密码",
          // onRightPressed: () => NavigatorUtils.push(
          //     context, AccountRouter.VERIFY_FORGET_PASSWORD),
        ),
        SizedBox(height: 290.h),
        XButton(
          key: const Key("login"),
          text: "登录",
          onPressed: state.isClickLogin ? _login : null,
        ),
        SizedBox(height: 40.h),
        XButton(
          key: const Key("register"),
          text: "注册",
          onPressed: () {
            LogUtil.v("=======> 注册");
          },
          textColor: Colors.white,
        ),
        SizedBox(height: 40.h),
      ];

  void _login() {
    controller.login(mobile: "15812341234", password: "123456");
  }
}
